package com.jnshu.controller;

import com.aliyuncs.exceptions.ClientException;
import com.jnshu.dto.user.UserVo;
import com.jnshu.service.BackUserService;
import com.jnshu.tools.resultUtils.ResultBean;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @ClassName BackUserController
 * @Descrintion
 * @Author bd
 * @Date 2019/8/7 22:53
 * @Version 1.0
 **/
@RestController
@Log
public class BackUserController {
    @Autowired
    BackUserService backUserService;

    /*
     * @Author bd
     * @Description 用户详情
     * @Date 22:59 2019/8/7
     * @Param [id]
     * @return com.jnshu.tools.resultUtils.ResultBean
     **/
    @GetMapping("/user")
    public ResultBean selectByPrimaryKey(@RequestParam(value = "id") long id) {
        log.info("controller层传入用户详情的id为" + id);
        return backUserService.selectByPrimaryKey(id);
    }

    @GetMapping("/user/list")
    //后台用户列表
    public ResultBean selectList(UserVo userVo, @RequestParam(defaultValue = "10") int pageSize,
                                 @RequestParam(defaultValue = "1") int pageNum) {
        log.info("controller层传入用户列表的id为user" + userVo + ",页面数量" + pageSize + ",页码" + pageNum);
        return backUserService.selectList(userVo, pageSize, pageNum);
    }

    @PostMapping(value = "/u/phone/code",produces ={"application/json;charset=UTF-8"})
    public ResultBean sendPhoneCode(String phone) throws ClientException {
        log.info("feign传入手机号码为："+phone);
        return backUserService.sendPhoneCode(phone);
    }

    @PostMapping(value = "/u/phone/binding",produces = {"application/json;charset=UTF-8"})
    public ResultBean bindingPhone(String phone,String code,Long id){
        log.info("feign传入的手机号码为："+phone+"，验证码："+code+"，用户id为："+id);
        return backUserService.bindingPhone(phone,code,id);
    }

    @PostMapping(value = "/u/my/email/code",produces = {"application/json;charset=UTF-8"})
    public ResultBean sendEmailCode(String email) throws IOException {
        log.info("feign传入的邮箱地址为："+email);
        return backUserService.sendEmailCode(email);
    }

    @PostMapping(value = "/u/my/email/binding",produces = {"application/json;charset=UTF-8"})
    public ResultBean bindingEmail(String email,String code, Long id){
        log.info("feign传入的邮箱地址为："+email+"，验证码为："+code+"，用户id为："+id);
        return backUserService.bindingEmail(email,code,id);
    }

}
